package com.example.softpart.magicAPiCustomFunction;


import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.example.softpart.unil.callMagicAPi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.ssssssss.magicapi.core.config.MagicFunction;
import org.ssssssss.magicapi.core.service.MagicAPIService;
import org.ssssssss.script.annotation.Comment;
import org.ssssssss.script.annotation.Function;

import java.util.HashMap;

@Component  //注入到Spring容器中
public class logFunction implements MagicFunction {

    @Autowired
    private MagicAPIService service;

    @Function
    @Comment("插入日志")
    public String  logInsert (String user_id,String operate,String operate_sql,String error_message,int is_success) {

        HashMap map = new HashMap();
        map.put("user_id",user_id);
        map.put("operate",operate);
        map.put("operate_sql",operate_sql);

        if (error_message.length()>0){
            map.put("error_message",error_message);
        }
        map.put("is_success",is_success);

        insertLog(map);


        return "";
    }


     public void insertLog(HashMap map){
        callMagicAPi.passCall(service, map, "POST", "/log/log");
    }


}
